<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="resources/css/stylemain.css">
<link rel="stylesheet" href="resources/layui/css/layui.css">
<link rel="stylesheet" href="resources/layui/css/treeTable.css">
<link rel="stylesheet" href="resources/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
</head>
<body>
<table class="layui-hide" id="tbl_locks" lay-filter="tbl_locks"></table>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">   
	<input style="width:150px;height:24px;font-size: 12px;" id="boxidsearch" class="ckinput" type="text" placeholder="箱号查询"></input> 
	<input style="width:150px;height:24px;font-size: 12px;margin-left:5px" id="locksearch" class="ckinput" type="text" placeholder="识别码查询"></input>
	
	<button type="button" id="btn_search" style="margin-left:5px" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="search"><i class="fa fa-search" aria-hidden="true"></i>查询</button>
  </div>
  </script>
<script type="text/javascript" src="resources/js/jquery.min.js"></script>
<script src="resources/layui/layui.all.js"></script>

<script type="text/javascript">
var table = layui.table;
var _slock = "";
var _sboxid = "";
var _mtype = 0;
var _slocks = [];
layui.use([], function(){
	table.on('toolbar(tbl_locks)', function(obj){
		//debugger;
		var checkStatus = table.checkStatus(obj.config.id);
		_sboxid = $('#boxidsearch').val();
		_slock = $('#locksearch').val();
		debugger;
		getSingleLockList();
	    
	});
	
});

$(document).ready(function(){
	$("#btn_search").click(function(){
		
	});
});

function child(slocks,mtype){
	debugger;
	_slocks = slocks;
	_mtype = mtype;
	getSingleLockList();
	
}

function getSingleLockList(){
	var datastring = '{"boxid":"' + _sboxid +'","locksn":"' + _slock + '"}';
	$.ajax({
		type:"post",
		contentType: "application/json;charset=UTF-8",
		url: "getSingleLockList_template.do?",
		data:datastring,
		async:false,
     	dataType:"json",
        success: function(msg) {    //数据提交成功时返回数据
        	//debugger;
        	if(msg.status == "1"){
				tablerender(msg);
			}else{
				layer.msg(msg.desc);
			}	
        	
        },        
        error : function(e){
            alert(e.status);
            alert(e.responseText);
        }

	});
	debugger;
   	if(_slocks != null){
   		for(var i=0,l=_slocks.length;i<l;i++){
   			var mydiv = $(":contains('"+ _slocks[i].locksn +"')").parent()[8].children[0].children[0].children[0];

            var $my=$(mydiv);
            $my.next('div').click();
   		 }
   	}
}

function tablerender(data){	
	table.render({
		  elem: '#tbl_locks'
		  ,toolbar: '#toolbarDemo'
		  ,cellMinWidth: 50
		  ,cols: [[
			  {type:'radio', hide: true}
			  ,{field:'locksn', title: '锁具识别码', width:160} 
			  ,{field:'oper_reals', title: '使用人'} 
			  ,{field:'boxid', title: '箱号', width:160} 
			  ,{field:'orgname', title: '所属机构'}
		  ]]
		  ,data:data.datalist
		  ,limit: Number.MAX_VALUE
		  ,height: '406',
		  done: function(res, curr, count){
		    $('#locksearch').val(_slock);
		    $('#boxidsearch').val(_sboxid);
		  }
		});	
	table.on('row(tbl_locks)', function(obj){
	    var data = obj.data;    
	    obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
		//选中radio样式
		obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
	});
}

function getCheckedLocks(){
	//debugger;
	var checkStatus = table.checkStatus('tbl_locks');
	var data = checkStatus.data;
	return data;
}

//监听表格选择
table.on('checkbox(tbl_locks)', function(obj){
	debugger;
    var mtr=obj.tr;
    var dx = obj.tr.children("td").children("div").children("div");
    var $dx =$(dx);
    if(obj.checked==true){
        $(mtr).css("color","green");
        $dx.addClass('layui-form-checked');

    }else{
        $(mtr).css("color","black");
        $dx.removeClass('layui-form-checked');
    }

});

</script>

</body>
</html>
